#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+10;
int T;
ll n,m,L,V,last;
ll d[maxn],a[maxn],v[maxn],l[maxn],ad[maxn];
void solveA(){
    int sum=0;
    for(int i=1;i<=n;i++){
        if(v[i]>V&&d[i]<=last)sum++;
        //cout<<v[i]<<" "<<V<<" "<<d[i]<<" "<<last<<endl;
    }
    if(sum==0)cout<<0<<" "<<m<<endl;
    else cout<<sum<<" "<<m-1<<endl;
    return ;
}
void solveB(){
    int sum=0;
    for(int i=1;i<=n;i++){
        ll xx=0;
        xx=(V*V-v[i]*v[i])/(2.0*a[i]);
        l[i]=xx+d[i]+1;
        if(v[i]==V)l[i]=d[i]+1;
        if(v[i]>V){
           l[i]=d[i];
            continue;
        }
    }
    for(int i=1;i<=n;i++)if(l[i]<=last)sum++;
    if(sum==0)cout<<0<<" "<<m<<endl;
    else cout<<sum<<" "<<m-1<<endl;
    return ;
}
void solve(){
    memset(d,0,sizeof(d));
    memset(a,0,sizeof(a));
    memset(v,0,sizeof(v));
    memset(l,0,sizeof(l));
    memset(ad,0,sizeof(ad));
    bool flagA=false,flagB=false;
    scanf("%lld%lld%lld%lld",&n,&m,&L,&V);
    for(int i=1;i<=n;i++){
        cin>>d[i]>>v[i]>>a[i];
        if(a[i]!=0)flagA=true;
        if(a[i]<=0)flagB=true;
    }
    last=0;
    for(int i=1;i<=m;i++){
        cin>>ad[i];
        if(ad[i]<=L)last=max(last,ad[i]);
    }
    if(!flagA){
        solveA();
        return ;
    }
    if(!flagB){
        solveB();
        return ;
    }
    cout<<m<<" "<<m<<endl;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        solve();
    }
    return 0;
}
